from peewee import *
from config.base_config import get_db
import datetime

db = get_db()


class CurrencyStrategy(Model):
    """
    定投策略类
    """
    id = IntegerField()
    base_asset = CharField()
    quote_asset = CharField()
    inst_type = CharField()
    inst_id = CharField()
    account_id = IntegerField()
    b_quantity = DecimalField()
    q_quantity = DecimalField()
    p_quantity = DecimalField() #每份下单金额
    cycle_interval = IntegerField()  # 间隔(小时)
    last_open_time = DateTimeField()
    create_time = DateTimeField(default=datetime.datetime.now())
    remark = CharField()
    status = IntegerField()  # 状态 0关闭，1开始，-1错误

    class Meta:
        database = db
        table_name = "currency_strategy"


class CurrencyOrder(Model):
    """
    定投订单类
    """
    id = IntegerField()
    strategy_id = IntegerField()
    buy_id = CharField()
    buy_price = DecimalField()
    buy_quantity = DecimalField()
    buy_time = DateTimeField(default=datetime.datetime.now())
    sell_id = CharField()
    sell_price = DecimalField()
    sell_quantity = DecimalField()
    sell_time = DateTimeField(default=datetime.datetime.now())
    status = IntegerField()

    class Meta:
        database = db
        table_name = "currency_order"
